home *** CD-ROM | disk | FTP | other *** search
- Path: abacus.abasoft.co.uk!not-for-mail
- From: dmb@abacus.abasoft.co.uk (David Byrne)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Calling System Command in SUN C
- Date: 14 Mar 1996 11:05:33 -0000
- Organization: Abacus Software Ltd.
- Message-ID: <4i8uht$1po@abacus.abasoft.co.uk>
- References: <4i1hlu$asm@ni1.ni.net> <4i41j0$8nu@dawn.mmm.com>
- NNTP-Posting-Host: abacus.abasoft.co.uk
- X-NNTP-Posting-Host: abacus.demon.co.uk
-
- In article <4i41j0$8nu@dawn.mmm.com>, Kevin J Hopps <kjhopps@mmm.com> wrote:
- >Ed Thomson (ethomson@cinahl.com) wrote:
- >> I am new to SUN C and am using version 3.0.1.
- >> I would like to execute a system command such as mail or a shell
- >> script I have generated and was wondering if anyone knew of an easy
- >> way to do this within C.
- >
- >The system(3S) function does what you want. You pass it a string
- >which is the command to execute. It returns the exit status of
- >the command.
-
- Close - the exit status you want is in the 8 high-order bits of the return
- value. On the Sun, you need to do something like
-
- {
- int status;
-
- errno = 0;
- status = system(cmd);
- if (status == 127)
- return(-1);
- return(status>>8);
- }
- --
- David Byrne, Abacus Software, London, UK Tel: +44 (0)171 603 9877
- Email: dmb@abacus.demon.co.uk Fax: +44 (0)171 603 6844
- Here's a koan: If you have ice-cream I will give you some. If you have none,
- I will take it away from you. (it's an ice-cream koan).
-